<?php
class Tourism_goods_profit_model extends CI_Model
{
    private $table = 'tourism_goods_profit';

    public function add($goods_attr_id, $postData)
    {
        $data = array();
        $result = true;
        if(!empty($postData['amount'])){
            foreach ($postData['amount'] as $key=>$value) {
                if($value > 0){
                    $data[] = array(
                        'status'        => $postData['status'],
                        'goods_attr_id' => $goods_attr_id,
                        'amount'        => trim($value),
                        'uid'           => trim($postData['uid'][$key]),
                        'bit_trade'     => trim($postData['type_id'][$key]),
                    );
                }
            }
            $result = $this->db->insert_batch($this->table, $data);
        }
        return $result;
    }

    public function delete($postData)
    {
        return $this->db->delete($this->table, array('goods_attr_id' => $postData['goods_attr_id'], 'status'=>$postData['status']));
    }

    public function findByArray($postData)
    {
        if (empty($postData)) {
            return false;
        }
        $this->db->select('*');
        $this->db->from($this->table);
        if (!empty($postData['goods_attr_id'])){
            $this->db->where('goods_attr_id', $postData['goods_attr_id']);
        }
        if (!empty($postData['status'])){
            $this->db->where('status', $postData['status']);
        }

        $result = $this->db->get();
        if ($result->num_rows() > 0){
            return $result;
        }
        return false;
    }
}